<!DOCTYPE html>
<html>
<body>
<script src="../../fast/dom/resources/event-sender-util.js"></script>
<script src="../../resources/js-test.js"></script>

<div id="host1"></div>
<div id="host2"></div>
<pre id="console"></pre>

<script>
function createBox(name) {
    var div = document.createElement('div');
    div.style.width = '100px';
    div.style.height = '100px';
    return div;
}

function createNestedShadowDOM(host, content) {
    var shadowRoot = host.attachShadow({mode: 'open'});
    var div = document.createElement('div');
    shadowRoot.appendChild(div);

    var nestedShadowRoot = div.attachShadow({mode: 'open'});
    var divInNestedShadowRoot = document.createElement('div');
    divInNestedShadowRoot.innerHTML = content;
    nestedShadowRoot.appendChild(divInNestedShadowRoot);

    return nestedShadowRoot;
}

var nestedShadowRoot1 = createNestedShadowDOM(host1, 'FUTAMI');
var nestedShadowRoot2 = createNestedShadowDOM(host2, 'AMAMI');

var div1 = nestedShadowRoot1.firstChild;
var div2 = nestedShadowRoot2.firstChild;

if (window.eventSender) {
    mouseMoveToElem(div2);
    eventSender.mouseDown();
    mouseMoveToElem(div1);
    eventSender.mouseUp();

    var selection2 = nestedShadowRoot2.getSelection();
    shouldBe('selection2.anchorNode', 'selection2.focusNode');

    shouldBe('selection2.anchorOffset', '5');
    shouldBe('selection2.focusOffset', '0');
}

var successfullyParsed = true;
</script>

</body>
</html>
